package body v8.Class_Handle.Class_Persistent is

   ------------
   -- Create --
   ------------

   function Create
     (Source : Pointer)
      return Persistent
   is
      function Invoke (Source_Handle : Pointer) return Persistent;
      pragma Import (CPP, Invoke, "_ZN2v82V818GlobalizeReferenceEPPNS_8internal6ObjectE");
   begin
      return Invoke (Source);
   end Create;
   pragma Inline(Create);

   -------------
   -- Dispose --
   -------------

   procedure Dispose (this : in out Persistent_Object) is
      procedure Invoke (Global_Handle : Pointer);
      pragma Import (CPP, Invoke, "_ZN2v82V813DisposeGlobalEPPNS_8internal6ObjectE");
   begin
      Invoke(this.As_Object);
   end Dispose;
   pragma Inline(Dispose);

   ---------------
   -- Make_Weak --
   ---------------

   procedure Make_Weak
     (this : in out Persistent_Object;
      Callback_Data : System.Address := System.Null_Address;
      Callback : Weak_Reference_Callback)
   is
      procedure Invoke
        (Global_Handle : Pointer;
         Data : Address;
         Callback : Weak_Reference_Callback);
      pragma Import(CPP, Invoke, "_ZN2v82V88MakeWeakEPPNS_8internal6ObjectEPvPFvNS_10PersistentINS_5ValueEEES5_E");
   begin
      Invoke (this.As_Object, Callback_Data, Callback);
   end Make_Weak;
   pragma Inline(Make_Weak);

   ----------------
   -- Clear_Weak --
   ----------------

   procedure Clear_Weak (this : in out Persistent_Object) is
      procedure Invoke (Global_Handle : Pointer);
      pragma Import(CPP, Invoke, "_ZN2v82V89ClearWeakEPPNS_8internal6ObjectE");
   begin
      Invoke (this.As_Object);
   end Clear_Weak;
   pragma Inline(Clear_Weak);

   ----------------------
   -- Mark_Independent --
   ----------------------

   procedure Mark_Independent (this : in out Persistent_Object) is
      procedure Invoke (global_handle : Pointer);
      pragma Import(CPP, Invoke, "_ZN2v82V815MarkIndependentEPPNS_8internal6ObjectE");
   begin
      Invoke (this.As_Object);
   end Mark_Independent;
   pragma Inline(Mark_Independent);

   -------------------
   -- Is_Near_Death --
   -------------------

   function Is_Near_Death (this : Persistent_Object) return Boolean is
      function Invoke
        (Global_Handle : Pointer
        ) return bool;
      pragma Import (CPP, Invoke, "_ZN2v82V817IsGlobalNearDeathEPPNS_8internal6ObjectE");
   begin
      return -Invoke (this.As_Object);
   end Is_Near_Death;
   pragma Inline(Is_Near_Death);

   -------------
   -- Is_Weak --
   -------------

   function Is_Weak (this : Persistent_Object) return Boolean is
      function Invoke
        (Global_Handle : Pointer
        ) return bool;
      pragma Import (CPP, Invoke, "_ZN2v82V812IsGlobalWeakEPPNS_8internal6ObjectE");
   begin
      return -Invoke (this.As_Object);
   end Is_Weak;
   pragma Inline(Is_Weak);

   --------------------------
   -- Set_Wrapper_Class_Id --
   --------------------------

   procedure Set_Wrapper_Class_Id
     (this     : in out Persistent_Object;
      Class_Id : uint16_t)
   is
      procedure Invoke
        (Global_Handle : Pointer;
         Class_Id : uint16_t);
      pragma Import (CPP, Invoke, "_ZN2v82V817SetWrapperClassIdEPPNS_8internal6ObjectEt");
   begin
      Invoke (this.As_Object, Class_Id);
   end Set_Wrapper_Class_Id;
   pragma Inline(Set_Wrapper_Class_Id);

end v8.Class_Handle.Class_Persistent;
